package com.github.xiaolyuh.manager;


import com.github.xiaolyuh.base.BasicCacheManager;
import com.github.xiaolyuh.dataloader.DataLoader;
import com.github.xiaolyuh.entity.CacheKey;
import com.github.xiaolyuh.entity.CacheValue;
import com.github.xiaolyuh.exception.CacheException;

public interface ICacheManager {

    /**
     * 根据指定的key，从缓存中获取对应的数据，如果数据不存在，则通过回调加载数据
     * @param cacheKey
     * @param clazz
     * @param dataLoader
     * @param distributeCacheManager
     * @param localCacheManager
     * @param <T>
     * @param <K>
     * @return
     * @throws CacheException
     */
    public <T, K> T get(CacheKey<K> cacheKey, Class<T> clazz, DataLoader<K, T> dataLoader, BasicCacheManager distributeCacheManager, BasicCacheManager localCacheManager) throws CacheException;

    /**
     * 根据指定的key，从缓存中批量获取对应的数据，如果数据不存在，则通过回调加载数据
     * @param cacheKeyList
     * @param clazz
     * @param dataLoader
     * @param distributeCacheManager
     * @param localCacheManager
     * @param <T>
     * @param <K>
     * @return
     * @throws CacheException
     */
    //public <T, K> Map<K, T> mget(List<CacheKey<K>> cacheKeyList, Class<T> clazz, DataLoader<K, T> dataLoader, BasicCacheManager distributeCacheManager, BasicCacheManager localCacheManager) throws CacheException;

    /**
     * 刷新对应的数据
     * @param cacheKey
     * @param clazz
     * @param dataLoader
     * @param async
     * @param distributeCacheManager
     * @param localCacheManager
     * @param <T>
     * @param <K>
     * @throws CacheException
     */
    public <T, K> void refresh(final CacheKey<K> cacheKey, final Class<T> clazz, final DataLoader<K, T> dataLoader, boolean async, BasicCacheManager distributeCacheManager, BasicCacheManager localCacheManager) throws CacheException;

    /**
     * 设置对应的缓存
     * @param cacheKey
     * @param cacheValue
     * @param distributeCacheManager
     * @param localCacheManager
     * @param <K>
     * @param <T>
     * @throws CacheException
     */
    public <K, T> void set(CacheKey<K> cacheKey, CacheValue<T> cacheValue, BasicCacheManager distributeCacheManager, BasicCacheManager localCacheManager) throws CacheException;

    /**
     * 设置对应的缓存(带空值)
     * @param cacheKey
     * @param cacheValue
     * @param distributeCacheManager
     * @param localCacheManager
     * @param <K>
     * @param <T>
     * @throws CacheException
     */
    public <K, T> void setWithFake(CacheKey<K> cacheKey, CacheValue<T> cacheValue, BasicCacheManager distributeCacheManager, BasicCacheManager localCacheManager) throws CacheException;


    /**
     * 删除对应的缓存
     * @param key
     * @param distributeCacheManager
     * @param localCacheManager
     * @return
     * @throws CacheException
     */
    public boolean delete(String key, BasicCacheManager distributeCacheManager, BasicCacheManager localCacheManager) throws CacheException;
}
